import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import Icon from '../../theme/input.svg';
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';


export default class contractUI extends Plugin {

    /**
     * @inheritDoc
     */
    init() {
        const editor = this.editor;
        const t = editor.t;

        // Setup `imageUpload` button.
        editor.ui.componentFactory.add('contract', locale => {
            const view = new ButtonView(locale);

            view.set({
                label: t('Insert tag'),
                icon: Icon,
                tooltip: true
            });

            // Callback executed once the image is clicked.
            view.on('execute', () => {
                const tag = prompt('标记名：');
                if (tag) {
                    editor.execute('contract', { value: tag });
                    editor.editing.view.focus();
                }
            });

            return view;
        });
    }
}